<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Comment
 *
 * @property int $id
 * @property int $user_id
 * @property int $topic_id
 * @property int|null $reply_comment_id
 * @property int|null $reply_user_id
 * @property string $content
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read Comment|null $belong_to_comment
 * @property-read \Illuminate\Database\Eloquent\Collection<int, Comment> $reply_comments
 * @property-read int|null $reply_comments_count
 * @property-read \App\Models\User|null $reply_user
 * @property-read \App\Models\Topic $topic
 * @property-read \App\Models\User $user
 * @method static \Database\Factories\CommentFactory factory($count = null, $state = [])
 * @method static \Illuminate\Database\Eloquent\Builder|Comment newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Comment newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Comment query()
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereReplyCommentId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereReplyUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereTopicId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Comment whereUserId($value)
 * @mixin \Eloquent
 */
class Comment extends Model
{
    use HasFactory;
    protected $fillable = ['content','user_id','reply_comment_id','reply_user_id'];
    protected $with = ['user','reply_user','belong_to_comment'];
    public function topic(){
        return $this->belongsTo(Topic::class);
    }

    public function user(){
        return $this->belongsTo(User::class);
    }

    public function reply_comments(){
        return $this->hasMany(Comment::class,'reply_comment_id');
    }

    public function  belong_to_comment(){
        return $this->belongsTo(Comment::class,'reply_comment_id');
    }

    public function reply_user(){
        return $this->belongsTo(User::class,'reply_user_id');
    }
}
